// The Encoder class implements a UTF-8 to Ascii and Ascii to UTF-8 encoding converters.

#include "../include/Encoder.h"
#include <iostream>
#include <fstream>


// Class constructor. Receives the encoding of the string we want to work on.
Encoder::Encoder(Poco::TextEncoding& enc) : encoding(enc) {}


// Converts the given string from UTF-8 encoding to Ascii
void Encoder::utf8ToAscii (string& message) {
	Poco::ASCIIEncoding asciiEncoding;
    Poco::TextConverter converter(encoding, asciiEncoding);
    string res;
    converter.convert(message, res);
    message = res;
}


// Converts the given string from Ascii encoding to UTF-8
void Encoder::asciiToUtf8 (string& message) {
	Poco::UTF8Encoding utf8Encoding;
	Poco::TextConverter converter(encoding, utf8Encoding);
	string res;
    converter.convert(message, res);
    message = res;
}
